package testproject;

import DAO.VacDAO;
import java.sql.Date;
import java.text.SimpleDateFormat;
import java.util.Vector;
import javax.swing.JOptionPane;
import static javax.swing.WindowConstants.DISPOSE_ON_CLOSE;

public class UpdateDeleteVac extends javax.swing.JFrame {

    VacDAO vacDAO = new VacDAO();
    String codeChoose;

    public UpdateDeleteVac(String codeChoose) {
        initComponents();

        setDefaultCloseOperation(DISPOSE_ON_CLOSE);
        
        this.codeChoose = codeChoose;
        lblVacDepNoCheck.setVisible(false);
        lblVacVacIdCheck.setVisible(false);
        lblVacDesID.setVisible(false);
        lblVacSecIdCheck.setVisible(false);
        lblVacNoofVacCheck.setVisible(false);
        lblVacStatusCheck.setVisible(false);
        lblVacDateCheck.setVisible(false);
        lblVacPriority.setVisible(false);

        vacDAO.loadVacCombobox(cbVacDepNo, cbVacDesId, cbVacSecId);

        loadUpdateToVac();
    }

    private UpdateDeleteVac() {
        
    }

    public void loadUpdateToVac() {
        Vector vecVacData = vacDAO.loadVacToUpdate(codeChoose.trim());

        txtVacVacId.setText(vecVacData.get(0).toString());
        cbVacDepNo.setSelectedItem(vecVacData.get(1).toString());
        cbVacSecId.setSelectedItem(vecVacData.get(2).toString());
        cbVacDesId.setSelectedItem(vecVacData.get(3).toString());
        txtVacNoofVac.setText(vecVacData.get(4).toString());
        txtVacStatus.setText(vecVacData.get(5).toString());
        jdVacDate.setDate(Date.valueOf(vecVacData.get(6).toString()));
        txtVacPriority.setText(vecVacData.get(7).toString());
    }

    public boolean validateUpdateDeleteVac() {
        if (txtVacVacId.getText().equals("")) {
            txtVacVacId.requestFocus();
            lblVacVacIdCheck.setVisible(true);
            return false;
        }
        if (!txtVacVacId.getText().matches("V{1}[0-9]{3,5}")) {
            txtVacVacId.requestFocus();
            lblVacVacIdCheck.setText("Vacancy ID need Follow Rule: V101");
            return false;
        }
        lblVacVacIdCheck.setVisible(false);
        if (cbVacDepNo.getSelectedIndex() == 0) {
            cbVacDepNo.requestFocus();
            lblVacDepNoCheck.setVisible(true);
            return false;
        }
        lblVacDepNoCheck.setVisible(false);
        if (cbVacSecId.getSelectedIndex() == 0) {
            cbVacSecId.requestFocus();
            lblVacSecIdCheck.setVisible(true);
            return false;
        }
        lblVacSecIdCheck.setVisible(false);
        if (cbVacDesId.getSelectedIndex() == 0) {
            cbVacDesId.requestFocus();
            lblVacDesID.setVisible(true);
            return false;
        }
        lblVacDesID.setVisible(false);
        if (txtVacNoofVac.getText().equals("")) {
            txtVacNoofVac.requestFocus();
            lblVacNoofVacCheck.setVisible(true);
            return false;
        }
        lblVacNoofVacCheck.setVisible(false);
        if (txtVacStatus.getText().equals("")) {
            txtVacStatus.requestFocus();
            lblVacStatusCheck.setVisible(true);
            return false;
        }
        lblVacStatusCheck.setVisible(false);
//        if (jdVacDate.getText().equals("")) {
//            jdVacDate.requestFocus();
//            lblVacDateCheck.setVisible(true);
//            return false;
//        }
        lblVacDateCheck.setVisible(false);
        if (txtVacPriority.getText().equals("")) {
            txtVacPriority.requestFocus();
            lblVacPriority.setVisible(true);
            return false;
        }
        lblVacPriority.setVisible(false);
        return true;
    }

    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jPUpdateDelteVac = new javax.swing.JPanel();
        jLabel6 = new javax.swing.JLabel();
        jLabel1 = new javax.swing.JLabel();
        jLabel5 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        jLabel7 = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        jLabel8 = new javax.swing.JLabel();
        jLabel4 = new javax.swing.JLabel();
        jLabel9 = new javax.swing.JLabel();
        btnVacUpdate = new javax.swing.JButton();
        btnVacDelete = new javax.swing.JButton();
        btnVacCancel = new javax.swing.JButton();
        txtVacVacId = new javax.swing.JTextField();
        txtVacNoofVac = new javax.swing.JTextField();
        txtVacStatus = new javax.swing.JTextField();
        txtVacPriority = new javax.swing.JTextField();
        cbVacDepNo = new javax.swing.JComboBox();
        cbVacSecId = new javax.swing.JComboBox();
        cbVacDesId = new javax.swing.JComboBox();
        lblVacVacIdCheck = new javax.swing.JLabel();
        lblVacDepNoCheck = new javax.swing.JLabel();
        lblVacSecIdCheck = new javax.swing.JLabel();
        lblVacDesID = new javax.swing.JLabel();
        lblVacNoofVacCheck = new javax.swing.JLabel();
        lblVacStatusCheck = new javax.swing.JLabel();
        lblVacDateCheck = new javax.swing.JLabel();
        lblVacPriority = new javax.swing.JLabel();
        jdVacDate = new com.toedter.calendar.JDateChooser();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setName("jfUpdateDeleteVac"); // NOI18N

        jLabel6.setFont(new java.awt.Font("Tahoma", 1, 24)); // NOI18N
        jLabel6.setForeground(new java.awt.Color(102, 102, 255));
        jLabel6.setText("Vacancy Registration");

        jLabel1.setForeground(new java.awt.Color(102, 102, 255));
        jLabel1.setText("Vacancy ID:");

        jLabel5.setForeground(new java.awt.Color(102, 102, 255));
        jLabel5.setText("No Of Vancacy:");

        jLabel2.setForeground(new java.awt.Color(102, 102, 255));
        jLabel2.setText("DeptNo:");

        jLabel7.setForeground(new java.awt.Color(102, 102, 255));
        jLabel7.setText("Status:");

        jLabel3.setForeground(new java.awt.Color(102, 102, 255));
        jLabel3.setText("Section ID:");

        jLabel8.setForeground(new java.awt.Color(102, 102, 255));
        jLabel8.setText("Vacancy Date:");

        jLabel4.setForeground(new java.awt.Color(102, 102, 255));
        jLabel4.setText("Designation ID:");

        jLabel9.setForeground(new java.awt.Color(102, 102, 255));
        jLabel9.setText("Priority:");

        btnVacUpdate.setForeground(new java.awt.Color(102, 102, 255));
        btnVacUpdate.setText("Update");
        btnVacUpdate.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnVacUpdateActionPerformed(evt);
            }
        });

        btnVacDelete.setForeground(new java.awt.Color(102, 102, 255));
        btnVacDelete.setText("Delete");
        btnVacDelete.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnVacDeleteActionPerformed(evt);
            }
        });

        btnVacCancel.setForeground(new java.awt.Color(102, 102, 255));
        btnVacCancel.setText("Cancel");

        txtVacVacId.setEditable(false);
        txtVacVacId.setForeground(new java.awt.Color(102, 102, 255));
        txtVacVacId.setEnabled(false);

        txtVacNoofVac.setForeground(new java.awt.Color(102, 102, 255));

        txtVacStatus.setForeground(new java.awt.Color(102, 102, 255));

        txtVacPriority.setForeground(new java.awt.Color(102, 102, 255));
        txtVacPriority.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                txtVacPriorityActionPerformed(evt);
            }
        });

        cbVacDepNo.setForeground(new java.awt.Color(102, 102, 255));
        cbVacDepNo.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Item 1", "Item 2", "Item 3", "Item 4" }));

        cbVacSecId.setForeground(new java.awt.Color(102, 102, 255));
        cbVacSecId.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Item 1", "Item 2", "Item 3", "Item 4" }));

        cbVacDesId.setForeground(new java.awt.Color(102, 102, 255));
        cbVacDesId.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Item 1", "Item 2", "Item 3", "Item 4" }));

        lblVacVacIdCheck.setForeground(new java.awt.Color(255, 0, 0));
        lblVacVacIdCheck.setText("Vacancy ID cannot be blank");

        lblVacDepNoCheck.setForeground(new java.awt.Color(255, 0, 0));
        lblVacDepNoCheck.setText("Please choice one DepNo");

        lblVacSecIdCheck.setForeground(new java.awt.Color(255, 0, 0));
        lblVacSecIdCheck.setText("Please choice onr Section ID");

        lblVacDesID.setForeground(new java.awt.Color(255, 0, 0));
        lblVacDesID.setText("Please choice one Designation ID");

        lblVacNoofVacCheck.setForeground(new java.awt.Color(255, 0, 0));
        lblVacNoofVacCheck.setText("No Of Vacancy cannot be blank");

        lblVacStatusCheck.setForeground(new java.awt.Color(255, 0, 0));
        lblVacStatusCheck.setText("Status cannot be blank");

        lblVacDateCheck.setForeground(new java.awt.Color(255, 0, 0));
        lblVacDateCheck.setText("Vacancy Date cannot be blank");

        lblVacPriority.setForeground(new java.awt.Color(255, 0, 0));
        lblVacPriority.setText("Priority cannot be blank");

        javax.swing.GroupLayout jPUpdateDelteVacLayout = new javax.swing.GroupLayout(jPUpdateDelteVac);
        jPUpdateDelteVac.setLayout(jPUpdateDelteVacLayout);
        jPUpdateDelteVacLayout.setHorizontalGroup(
            jPUpdateDelteVacLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPUpdateDelteVacLayout.createSequentialGroup()
                .addGroup(jPUpdateDelteVacLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPUpdateDelteVacLayout.createSequentialGroup()
                        .addGap(23, 23, 23)
                        .addGroup(jPUpdateDelteVacLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(jPUpdateDelteVacLayout.createSequentialGroup()
                                .addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 90, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(txtVacVacId, javax.swing.GroupLayout.PREFERRED_SIZE, 200, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addGroup(jPUpdateDelteVacLayout.createSequentialGroup()
                                .addGroup(jPUpdateDelteVacLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(jLabel2, javax.swing.GroupLayout.PREFERRED_SIZE, 90, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addComponent(jLabel4, javax.swing.GroupLayout.PREFERRED_SIZE, 90, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addComponent(jLabel3, javax.swing.GroupLayout.PREFERRED_SIZE, 90, javax.swing.GroupLayout.PREFERRED_SIZE))
                                .addGroup(jPUpdateDelteVacLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addGroup(jPUpdateDelteVacLayout.createSequentialGroup()
                                        .addGap(34, 34, 34)
                                        .addComponent(btnVacUpdate, javax.swing.GroupLayout.PREFERRED_SIZE, 100, javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addGap(33, 33, 33)
                                        .addComponent(btnVacDelete, javax.swing.GroupLayout.PREFERRED_SIZE, 100, javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addGap(32, 32, 32)
                                        .addComponent(btnVacCancel, javax.swing.GroupLayout.PREFERRED_SIZE, 100, javax.swing.GroupLayout.PREFERRED_SIZE))
                                    .addGroup(jPUpdateDelteVacLayout.createSequentialGroup()
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                        .addGroup(jPUpdateDelteVacLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                            .addComponent(cbVacDepNo, javax.swing.GroupLayout.PREFERRED_SIZE, 200, javax.swing.GroupLayout.PREFERRED_SIZE)
                                            .addComponent(cbVacSecId, javax.swing.GroupLayout.PREFERRED_SIZE, 200, javax.swing.GroupLayout.PREFERRED_SIZE)
                                            .addComponent(cbVacDesId, javax.swing.GroupLayout.PREFERRED_SIZE, 200, javax.swing.GroupLayout.PREFERRED_SIZE)
                                            .addComponent(lblVacVacIdCheck, javax.swing.GroupLayout.PREFERRED_SIZE, 200, javax.swing.GroupLayout.PREFERRED_SIZE)
                                            .addComponent(lblVacDepNoCheck, javax.swing.GroupLayout.PREFERRED_SIZE, 200, javax.swing.GroupLayout.PREFERRED_SIZE)
                                            .addComponent(lblVacSecIdCheck, javax.swing.GroupLayout.PREFERRED_SIZE, 200, javax.swing.GroupLayout.PREFERRED_SIZE)
                                            .addComponent(lblVacDesID, javax.swing.GroupLayout.PREFERRED_SIZE, 200, javax.swing.GroupLayout.PREFERRED_SIZE))
                                        .addGap(69, 69, 69)
                                        .addGroup(jPUpdateDelteVacLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                                            .addGroup(jPUpdateDelteVacLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                                .addGroup(jPUpdateDelteVacLayout.createSequentialGroup()
                                                    .addComponent(jLabel7, javax.swing.GroupLayout.PREFERRED_SIZE, 90, javax.swing.GroupLayout.PREFERRED_SIZE)
                                                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                                    .addComponent(txtVacStatus, javax.swing.GroupLayout.PREFERRED_SIZE, 200, javax.swing.GroupLayout.PREFERRED_SIZE))
                                                .addGroup(jPUpdateDelteVacLayout.createSequentialGroup()
                                                    .addComponent(jLabel5, javax.swing.GroupLayout.PREFERRED_SIZE, 90, javax.swing.GroupLayout.PREFERRED_SIZE)
                                                    .addGap(18, 18, 18)
                                                    .addComponent(txtVacNoofVac, javax.swing.GroupLayout.PREFERRED_SIZE, 200, javax.swing.GroupLayout.PREFERRED_SIZE))
                                                .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPUpdateDelteVacLayout.createSequentialGroup()
                                                    .addGroup(jPUpdateDelteVacLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                                        .addComponent(jLabel9, javax.swing.GroupLayout.PREFERRED_SIZE, 90, javax.swing.GroupLayout.PREFERRED_SIZE)
                                                        .addComponent(jLabel8, javax.swing.GroupLayout.PREFERRED_SIZE, 90, javax.swing.GroupLayout.PREFERRED_SIZE))
                                                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                                    .addGroup(jPUpdateDelteVacLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                                        .addComponent(txtVacPriority, javax.swing.GroupLayout.DEFAULT_SIZE, 200, Short.MAX_VALUE)
                                                        .addComponent(lblVacStatusCheck, javax.swing.GroupLayout.DEFAULT_SIZE, 200, Short.MAX_VALUE)
                                                        .addComponent(lblVacDateCheck, javax.swing.GroupLayout.DEFAULT_SIZE, 200, Short.MAX_VALUE)
                                                        .addComponent(lblVacPriority, javax.swing.GroupLayout.DEFAULT_SIZE, 200, Short.MAX_VALUE)
                                                        .addComponent(jdVacDate, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))))
                                            .addComponent(lblVacNoofVacCheck, javax.swing.GroupLayout.PREFERRED_SIZE, 200, javax.swing.GroupLayout.PREFERRED_SIZE)))))))
                    .addGroup(jPUpdateDelteVacLayout.createSequentialGroup()
                        .addGap(217, 217, 217)
                        .addComponent(jLabel6)))
                .addContainerGap(55, Short.MAX_VALUE))
        );
        jPUpdateDelteVacLayout.setVerticalGroup(
            jPUpdateDelteVacLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPUpdateDelteVacLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel6)
                .addGap(18, 18, 18)
                .addGroup(jPUpdateDelteVacLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addGroup(jPUpdateDelteVacLayout.createSequentialGroup()
                        .addGroup(jPUpdateDelteVacLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addGroup(jPUpdateDelteVacLayout.createSequentialGroup()
                                .addGroup(jPUpdateDelteVacLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                    .addComponent(jLabel1)
                                    .addComponent(txtVacVacId, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addComponent(jLabel5)
                                    .addComponent(txtVacNoofVac, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                                .addGap(18, 18, 18)
                                .addGroup(jPUpdateDelteVacLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                    .addComponent(lblVacVacIdCheck)
                                    .addComponent(lblVacNoofVacCheck))
                                .addGap(15, 15, 15)
                                .addGroup(jPUpdateDelteVacLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addGroup(jPUpdateDelteVacLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                        .addComponent(jLabel2)
                                        .addComponent(cbVacDepNo, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                                    .addComponent(jLabel7)))
                            .addComponent(txtVacStatus, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(18, 18, 18)
                        .addGroup(jPUpdateDelteVacLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(lblVacDepNoCheck)
                            .addComponent(lblVacStatusCheck))
                        .addGap(18, 18, 18)
                        .addGroup(jPUpdateDelteVacLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel3)
                            .addComponent(jLabel8)
                            .addComponent(cbVacSecId, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(15, 15, 15)
                        .addComponent(lblVacSecIdCheck))
                    .addGroup(jPUpdateDelteVacLayout.createSequentialGroup()
                        .addComponent(jdVacDate, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(18, 18, 18)
                        .addComponent(lblVacDateCheck)))
                .addGap(18, 18, 18)
                .addGroup(jPUpdateDelteVacLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jLabel4)
                    .addGroup(jPUpdateDelteVacLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(jLabel9)
                        .addComponent(txtVacPriority, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(cbVacDesId, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addGap(15, 15, 15)
                .addGroup(jPUpdateDelteVacLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(lblVacDesID)
                    .addComponent(lblVacPriority))
                .addGap(18, 18, 18)
                .addGroup(jPUpdateDelteVacLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(btnVacCancel)
                    .addComponent(btnVacUpdate)
                    .addComponent(btnVacDelete))
                .addContainerGap(40, Short.MAX_VALUE))
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jPUpdateDelteVac, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jPUpdateDelteVac, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void btnVacUpdateActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnVacUpdateActionPerformed
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        if (validateUpdateDeleteVac()) {

            String VacID = txtVacVacId.getText().trim();
            int DepNo = Integer.parseInt(cbVacDepNo.getSelectedItem().toString().trim());
            String SecID = cbVacSecId.getSelectedItem().toString().trim();
            String DesignID = cbVacDesId.getSelectedItem().toString().trim();
            int NoofVac = Integer.parseInt(txtVacNoofVac.getText().trim());
            String Status = txtVacStatus.getText();
            String VacDate = sdf.format(jdVacDate.getDate());
            String Priority = txtVacPriority.getText().trim();

            Vector v = new Vector();
            v.add(VacID);
            v.add(DepNo);
            v.add(SecID);
            v.add(DesignID);
            v.add(NoofVac);
            v.add(Status);
            v.add(VacDate);
            v.add(Priority);

            if (!validateUpdateDeleteVac()) {
                return;
            }

            if (!vacDAO.updatateVac(v)) {
                JOptionPane.showMessageDialog(this, "Cannot Insert! Please try again!", "INSERT VACANCIES", JOptionPane.ERROR_MESSAGE);
                return;
            }
            JOptionPane.showMessageDialog(this, "Insert new VACANCIES successfully!", "INSERT VACANCIES", JOptionPane.INFORMATION_MESSAGE);
        }
    }//GEN-LAST:event_btnVacUpdateActionPerformed

    private void txtVacPriorityActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_txtVacPriorityActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_txtVacPriorityActionPerformed

    private void btnVacDeleteActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnVacDeleteActionPerformed

        String VacID = txtVacVacId.getText().trim();

        if (!vacDAO.deleteVac(VacID)) {
            JOptionPane.showMessageDialog(this, "Cannot DELETE! Please try again!", "DELETE VACANCIES", JOptionPane.ERROR_MESSAGE);
            return;
        }
        JOptionPane.showMessageDialog(this, "DELETE VACANCIES successfully!", "DELETE VACANCIES", JOptionPane.INFORMATION_MESSAGE);

    }//GEN-LAST:event_btnVacDeleteActionPerformed

    public static void main(String args[]) {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(UpdateDeleteVac.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(UpdateDeleteVac.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(UpdateDeleteVac.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(UpdateDeleteVac.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /* Create and display the form */
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new UpdateDeleteVac().setVisible(true);
            }
        });
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btnVacCancel;
    private javax.swing.JButton btnVacDelete;
    private javax.swing.JButton btnVacUpdate;
    private javax.swing.JComboBox cbVacDepNo;
    private javax.swing.JComboBox cbVacDesId;
    private javax.swing.JComboBox cbVacSecId;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JLabel jLabel9;
    private javax.swing.JPanel jPUpdateDelteVac;
    private com.toedter.calendar.JDateChooser jdVacDate;
    private javax.swing.JLabel lblVacDateCheck;
    private javax.swing.JLabel lblVacDepNoCheck;
    private javax.swing.JLabel lblVacDesID;
    private javax.swing.JLabel lblVacNoofVacCheck;
    private javax.swing.JLabel lblVacPriority;
    private javax.swing.JLabel lblVacSecIdCheck;
    private javax.swing.JLabel lblVacStatusCheck;
    private javax.swing.JLabel lblVacVacIdCheck;
    private javax.swing.JTextField txtVacNoofVac;
    private javax.swing.JTextField txtVacPriority;
    private javax.swing.JTextField txtVacStatus;
    private javax.swing.JTextField txtVacVacId;
    // End of variables declaration//GEN-END:variables
}
